<?
//define('IN_INDEX', TRUE);

session_start();
/* Load required lib files. */
require_once('JSON/JSON.php');
require_once('twitteroauth/twitteroauth.php');
require_once('config.php');
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN">
<head>
<title>twitter status</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css"
	href="../templates/<? echo $settings['template'] ?>/style_lp.css"
	media="all" />
</head>
<body>
<style type ="text/css" >

.woork{
	color:#444;
	font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;
	font-size:12px;
	width:600px;
	margin: 0 auto;
}
.twitter_container{
	color:#444;
	font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;
	font-size:12px;
	width:600px;
	margin: 0 auto;
}
.twitter_container a{
	color:#0066CC;
	font-weight:bold;
}
.twitter_status{
	height:60px;
	padding:6PX;
	border-bottom:solid 1px #DEDEDE;
}
.twitter_image{
	float:left; 
	margin-right:14px;
	border:solid 2px #DEDEDE;
	width:50px;
	height:50px;
}
.twitter_posted_at{
 font-size:11px;
 padding-top:4px;
 color:#999;
}
</style>
<div class="twitter_container">
<?

/* If access tokens are not available redirect to connect page. */
	if (empty($_SESSION['access_token']) ) 
	{
	echo "empty access token, should re-require auth toen";
	/*	$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
		$request_token = $connection->getRequestToken(OAUTH_CALLBACK);
		$_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
		$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
		switch ($connection->http_code) {
		  case 200:
		    $url = $connection->getAuthorizeURL($token);
		    echo " return url = ". $url; 
		    break;
		  default:
		    echo 'Could not connect to Twitter. Refresh the page or try again later.';
		    break;
		}
		*/
	}
	/* If access tokens are not available redirect to connect page. */
	if (!(empty($_SESSION['access_token'])))
	{
		/* Get user access tokens out of the session. */
		$access_token = $_SESSION['access_token'];
		/* Create a TwitterOauth object with consumer/user tokens. */
		$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
		/* If method is set change API call made. Test is called by default. */
		$content = $connection->get('account/rate_limit_status');
		echo "Current API hits remaining: {$content->remaining_hits}.";
		  
		  $user = $connection->get('account/verify_credentials');

		  
		//$method = 'statuses/public_timeline';
		$method = 'statuses/user_timeline';
		$parameters = array('count' => '10');
		
		//$response = $connection->get('statuses/public_timeline');
		$response = $connection->get($method, $parameters);
		
		
		foreach($response as $status){
			echo '<div class="twitter_status">';
		/*	foreach($status  as $user){
				echo '<img src="'.$user->profile_image_url.'" class="twitter_image">'; 
				echo '<a href="http://www.twitter.com/'.$user->name.'">'.$user->name.'</a>: '; 
			}*/ 
			$user = $status ->user;
			echo '<img src="'.$user->profile_image_url.'" class="twitter_image">'; 
			echo '<a href="http://www.twitter.com/'.$user->screen_name.'">'.$user->name.'</a>: '; 
			echo $status->text;
			echo '<br/>';
			echo '<div class="twitter_posted_at"><strong>Posted at:</strong> '.$status->created_at.'</div>';
			echo '</div>';
		}

	}
?>
</div>
</body>
</html>
